<extend name="Public/base" />

<block name="body">

<!-- 标题栏 -->
<div class="main-title">
    <h2>数据列表</h2>
</div>
<div class="data" style="display: none;">
<select id="data-nickname" name="li[username]">
<volist name="member" id="vo">
<option value='{$vo.nickname}'>{$vo.nickname}</option>
</volist>
</select>
</div>
<div class="dataname" style="display: none;">
<select id="data-name" name="li[name]">
<volist name="category" id="vo">
<option value='{$vo.name}'>{$vo.name}</option>
</volist> 
</select>
</div>
<div class="panel panel-default">
    <div class="panel-heading">     
        <div class="fl">
            <button style="background: none;border: none;">
                <form action="{:U('loan/data_export')}" method="post">   
                    <input type="submit" class="btn btn-info button" value="导出全部">
                </form>
            </button>
            <button style="background: none;border: none;">
                <form action="{:U('loan/data_export?where=today')}" method="post">   
                    <input type="submit" class="btn btn-info button" value="导出当天">
                </form>
            </button>
            <!-- <button   class="add_product btn btn-default c_green">新 增</button>  
            <button id="jq2excel" class="btn btn-info">导 出</button> 
            <div class="_input" style="float: right;">
                 <form action="{:U('product')}" method="post">
                    <input type="text" name="search_name" class="search_name" placeholder="搜索用户名" value="{$search_name}"> 
                    <input type="hidden" id="product_type_id" value="{$product_type_id}"/>
                    <select name="search_id" style="width: 150px;" id="search_id">
                        <option value="0">产品分类</option>
                        <volist name="data" id="vo">
                           <option value="{$vo.id}">{$vo.name}</option>             
                        </volist>   
                    </select>
                    <input  type="submit"  class="btn btn-warning search" value="查询">
                </form>
            </div>
            <a href="{:U('product_type')}">
                <button  class=" btn btn-default ">产品分类</button>
            </a> -->
        </div>      
    </div><!-- /.panel-heading --> 
    
    <div class="panel-body">
        <div class="table-responsive">      
            <table class="table table-striped table-bordered table-hover" id="dataTables-mydocment"><!-- 必须设定表格的id == -->
                <thead>
                    <tr>
                    
                    <th class="">ID</th>
                    <th width=60 class="">姓名</th>
                    <th class="">电话</th>
                    <th width=70 class="">年龄</th>
                    <th width="110" class="">城市</th>
                    <th class="">居住工作时间</th>
                    <th class="">此城市是否有房贷</th>
                    <th class="">名下有私家车</th>
                    <th class="">目前还在还车贷</th>
                    <th class="">购买过寿险保单</th>
                    <th class="">名下寿险年费保费合计</th>
                    <th class="">时间</th>
                    <th class="">操作</th>
                </tr>
                </thead>
                <tbody>
                    <volist name="data" id="vo">
                    <tr>
                        <td>{$vo.id} </td>
                        <td>{$vo.username} </td>
                        <td><a href="{:U('Article/index?cate_id='.$vo['category_id'].'&pid='.$vo['id'])}">{$vo.mobile}</a></td>
                        <td><span>{:getAge($vo['age'])}</span></td>
                        <td><span>{$vo.city}</span></td>
                        <td><span>{:getWorkTime($vo['workTime'])}</span></td>
                        
                        <td><span>{:getYesNo($vo['houseLoan'])}</span></td>
                        <td>{:getYesNo($vo['car'])}</td>
                        <td><span>{:getYesNo($vo['carloan'])}</span></td>
                       
                        <td>{:getYesNo($vo['insurance'])}</td>
                        <td>{:getInsuranceFee($vo['insuranceFee'])}</td>
                       
                        <td>{$vo.createtime|time_format} </td>
                        <td>  <a class="dis_b del_data" data-id="{$vo.id}"> 
                          <button class="btn  ajax-get confirm" href="{:U('delete',array('id'=>$vo['id']))}" url="{:U('loan/index')}" target-form="ids">删除</button>
                        </a> </td>
                    </tr>
                    </volist>
                </tbody>
            </table>
        </div><!-- /.table-responsive --> 
    </div><!-- /.panel-body -->
    <!-- 分页 -->
    <div class="page">
        {$_page}
    </div>
</div><!-- /.panel --> 
</block> 
<block name="script">
<link rel="stylesheet" href="__STATIC__/datetimepicker/css/datetimepicker.css" /> 
<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
<script src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>   
<script type="text/javascript" src="__JS__/jquery.table2excel.min.js"></script> 
  

<script type="text/javascript">
    
var product_type_id =  $("#product_type_id").val();
    $("#search_id option[value='"+product_type_id+"']").attr("selected","selected");        
    $(".search_name").focus(function(){
        $(this).val("")     
    })


$('#goback').on('click',function () {
    $('#addshow').hide();
}) 
$('.edit').on('click',function () {
    var dataId = $(this).parent().attr('data-id');
    $.ajax({
            type:"post",
            url:"__URL__/show",
            data:{ID:dataId},
            success:function(data){ 
               $('#ids').val(data[0]['id']);
               $('#number').val(data[0]['number']);
               $('#name').val(data[0]['name']);
               $('#name').val(data[0]['name']);
               $('#specification').val(data[0]['specification']);
               $('#category').val(data[0]['category']);
               $('#remark').val(data[0]['remark']); 
            }
          });
})
//编辑产品
var _htm =  
    "<form id='_form' name='myform' method='post' role='form'>"+ 
        "<div class='add_record'>"+
            "<div>"+
                "<ul>"+  
                    "<li class='c_f'>"+
                        "<span>产品ID</span>"+
                        "<input type='text' id='ids' name = 'id' style = 'background:#ccc' readonly>"+
                    "</li>"+ 
                    "<li class='c_f'>"+
                        "<span>产品编号</span>"+
                        "<input type='text' id='number' name = 'number' readonly style = 'background:#ccc'>"+
                    "</li>"+
                    "<li class='c_f'>"+
                        "<span>产品名称</span>"+
                        "<input type='text' id='name' name='name' >"+
                    "</li>"+
                    "<li class='c_f'>"+
                        "<span>规格</span>"+
                        "<input type='text' id='specification' name = 'specification'>"+  
                    "</li>"+ 
                    
                    "<li class='c_f'>"+
                        "<span>产品分类</span>"+
                         "<input type='text' id='category' name='category'>"+
                    "</li>"+ 
                    "<li class='c_f'>"+
                        "<span>备注</span>"+
                         "<input type='text' id='remark' name='remark'>"+
                    "</li>"+     
                    "<p>"+
                        "<button class='btn btn-default c_green' id='editsubmit' >确 定</button>"+ 
                    "</p>"+ 
                "</ul>"+
            "</div>"+
        "</div>"+ 
    "</form>";
    // 新增产品
 var _htms =  
    "<form id='_form' name='myform' method='post' role='form'>"+ 
        "<div class='add_record'>"+
            "<div>"+
                "<ul>"+ 
                    "<li class='c_f'>"+
                        "<span>类型</span>"+
                        "<select name='product_type'>"+
                            "<option value='0'>产品</option>"+
                            "<option value='1'>配件</option>"+ 
                        "</select>"+
                    "</li>"+  
                    "<li class='c_f'>"+
                        "<span>产品名称</span>"+
                        "<input type='text' id='name' name='name' >"+
                    "</li>"+
                    "<li class='c_f'>"+
                        "<span>规格</span>"+
                        "<input type='text' id='specification' name = 'specification'>"+  
                    "</li>"+ 
                    
                    "<li class='c_f'>"+
                        "<span>产品分类</span>"+
                        "<select id='category' name='category'>"+
    
                        "</select>"+
                    "</li>"+ 
                    "<li class='c_f'>"+
                        "<span>备注</span>"+
                         "<input type='text' id='remark' name='remark'>"+
                    "</li>"+     
                    "<p>"+
                        "<button class='submit btn btn-default c_green'  >确 定</button>"+ 
                    "</p>"+ 
                "</ul>"+
            "</div>"+
        "</div>"+ 
    "</form>";

//弹出框 - 新增记录层
$('.add_product').click(function(){ 
   
    $.get("{:U('category')}",function(data){
        console.log(data);
        for(var i = 0;i<data.length;i++){           
            var op = "<option value = "+data[i].id+">"+data[i].name+"</option>"
            $("#category").append(op);
        }
    })
    layer.open({  
      title: '新增产品', 
      type: 1,
      skin: 'layui-layer-rim', //加上边框
      area: ['500px', '700px'], //宽高
      content: _htms
    });
});    

//弹出框 - 编辑记录层
$('.edit').click(function(){
    //编辑层
    layer.open({  
      title: '产品修改', 
      type: 1,
      skin: 'layui-layer-rim', //加上边框
      area: ['500px', '700px'], //宽高
      content: _htm
    });
});

//修改产品
var boole = true;
$(document).on('click','#editsubmit',function(){
    $('.add_record ul li').each(function(){
        var input = $(this).find('input').val();  
        if(input == ''){
            boole = false;
            layer.msg('请填写完整内容!'); 
            return false;
        }else{
            boole = true;
        }
    });   
    if(boole){        
          var info = $('#_form').serialize();         
          $.ajax({
            type:"post",
            url:"__URL__/edit",
            data:info,
            async:true,
            success:function(data){
                layer.msg(data.msg);
                window.location.reload(); 
            }
          });
    }  
    return false;
});

$(document).on('click','.submit',function(){
    $('.add_record ul li').each(function(){
        var input = $(this).find('input').val();  
        if(input == ''){
            boole = false;
            layer.msg('请填写完整内容!'); 
            return false;
        }else{
            boole = true;
        }
    });   
    if(boole){        
          var info = $('#_form').serialize();         
          $.ajax({
            type:"post",
            url:"__URL__/product_add",
            data:info,
            async:true,
            success:function(data){
                window.location.reload(); 
            }
          });
    }  
    return false;
});

</script>
 
</block>
